package com.renren.project.db.validator.account;

import com.renren.project.db.validator.ValidationUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 登录账号验证
 * @date 2019年5月15日 下午4:51:30
 */
public class AccountValidationImpl implements ConstraintValidator<AccountValidation,String>{
	
	private boolean required = false;

	private int verifyType;

	@Override
	public void initialize(AccountValidation constraintAnnotation) {
		required = constraintAnnotation.required();
		this.verifyType = constraintAnnotation.verifyType();
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if(required){
            return ValidationUtils.isAcconut(value,verifyType);
        }else{
            if(StringUtils.isBlank(value)){
                return true;
            }else{
                return ValidationUtils.isAcconut(value,verifyType);
            }
        }
	}

}
